package course.p7_binaryTree.s1_NorBinaryNode;

import org.junit.Test;

public class NorBinaryTreeTest {


    private final String LEVEL = "Level";
    private final String BEFORE = "B";
    private final String F_BEFORE = "FB";
    private final String MEDIA = "M";
    private final String F_MEDIA = "FM";
    private final String AFTER = "A";
    private final String F_AFTER = "FA";

    /**
     * add方法测试
     */
    @Test
    public void addTest(){
        NorBinaryTree binaryTree = new NorBinaryTree();
        for(int i=0;i<7;i++){
            binaryTree.add(i);
        }
        binaryTree.traverse(LEVEL);
    }

    @Test
    public void deleteTest(){
        NorBinaryTree binaryTree = new NorBinaryTree();
        for(int i=0;i<7;i++){
            binaryTree.add(i);
        }
        binaryTree.traverse(LEVEL);
        binaryTree.delete(1);
        binaryTree.traverse(LEVEL);
    }

    @Test
    public void updateTest(){
        NorBinaryTree binaryTree = new NorBinaryTree();
        for(int i=0;i<7;i++){
            binaryTree.add(i);
        }
        binaryTree.traverse(LEVEL);
        binaryTree.update(2,10);
        binaryTree.traverse(LEVEL);
    }

    /**
     * 遍历方法测试
     */
    @Test
    public void traverseTest(){
        NorBinaryTree binaryTree = new NorBinaryTree();
        for(int i=0;i<20;i++){
            binaryTree.add(i);
        }
        binaryTree.traverse(LEVEL);
        binaryTree.traverse(BEFORE);
        binaryTree.traverse(F_BEFORE);
        System.out.println();
        binaryTree.traverse(MEDIA);
        binaryTree.traverse(F_MEDIA);
        System.out.println();
        binaryTree.traverse(AFTER);
        binaryTree.traverse(F_AFTER);
    }

    @Test
    public void levelOrderTest(){
        NorBinaryTree binaryTree = new NorBinaryTree();
        for(int i=0;i<20;i++){
            binaryTree.add(i);
        }
        binaryTree.traverse(LEVEL);
    }

    @Test
    public void buildTree(){
        int[] preorder = {3,9,20,15,7};
        int[] inorder = {9,3,15,20,7};
        NorBinaryTree tree = new NorBinaryTree();
        tree.buildBinaryTree(preorder,inorder);
        tree.traverse(LEVEL);
    }

}
